"curl 0.0.1 (git+https://github.com/alexcrichton/curl-rust?ref=bundle#36b015de91daf6310227cec04ef30acf5929dfb6)",
"docopt 0.6.4 (git+https://github.com/docopt/docopt.rs#4544a9f422b115c2ffef4ee9baf27ceb07c34602)",
"flate2 0.0.1 (git+https://github.com/alexcrichton/flate2-rs#68971ae77a523c7ec3f19b4bcd195f76291ea390)",
- "git2 0.0.1 (git+https://github.com/alexcrichton/git2-rs#c01b0b279470552c48cf7f902ae5baf132df0a6d)",
+ "git2 0.0.1 (git+https://github.com/alexcrichton/git2-rs#7d7fba10893590793ae88c8fc6ab2aeffcb8f10b)",
"glob 0.0.1 (git+https://github.com/rust-lang/glob#469a6bc1a0fc289ab220170e691cffbc01dcf1e6)",
"hamcrest 0.1.0 (git+https://github.com/carllerche/hamcrest-rust.git#7d46e76514ac606530dfb0e93270fffcf64ca76d)",
"semver 0.1.0 (git+https://github.com/rust-lang/semver#9bb8265ea6cf01eddfa7dc5ec9334883443e9fc7)",
[[package]]
name = "git2"
version = "0.0.1"
-source = "git+https://github.com/alexcrichton/git2-rs#c01b0b279470552c48cf7f902ae5baf132df0a6d"
+source = "git+https://github.com/alexcrichton/git2-rs#7d7fba10893590793ae88c8fc6ab2aeffcb8f10b"
dependencies = [
- "libgit2 0.0.1 (git+https://github.com/alexcrichton/git2-rs#c01b0b279470552c48cf7f902ae5baf132df0a6d)",
+ "libgit2 0.0.1 (git+https://github.com/alexcrichton/git2-rs#7d7fba10893590793ae88c8fc6ab2aeffcb8f10b)",
"url 0.1.0 (git+https://github.com/servo/rust-url#7f1991d847fb8cf8648def2ff121bae90b89131f)",
]
[[package]]
name = "libgit2"
version = "0.0.1"
-source = "git+https://github.com/alexcrichton/git2-rs#c01b0b279470552c48cf7f902ae5baf132df0a6d"
+source = "git+https://github.com/alexcrichton/git2-rs#7d7fba10893590793ae88c8fc6ab2aeffcb8f10b"
dependencies = [
"libssh2-static-sys 0.0.1 (git+https://github.com/alexcrichton/libssh2-static-sys#80e71a3021618eb05656c58fb7c5ef5f12bc747f)",
"link-config 0.0.1 (git+https://github.com/alexcrichton/link-config#0202cc8aa74a7b0bdbaef4eef368d0bc80f63691)",
})
}
+fn existing_git_repo(path: &Path) -> bool {
+ GitRepo::discover(path).is_ok()
+}
+
fn mk(path: &Path, name: &str, opts: &NewOptions) -> CargoResult<()> {
let cfg = try!(global_config());
let mut ignore = "/target\n".to_string();
+ let no_git = !opts.git && (opts.no_git || cfg.git == Some(false));
+ let in_existing_git_repo = existing_git_repo(&path.dir_path());
if !opts.bin {
ignore.push_str("/Cargo.lock\n");
}
if opts.hg {
try!(HgRepo::init(path));
try!(File::create(&path.join(".hgignore")).write(ignore.as_bytes()));
- } else if !opts.git && (opts.no_git || cfg.git == Some(false)) {
+ } else if no_git || in_existing_git_repo {
try!(fs::mkdir(path, io::USER_RWX));
} else {
try!(GitRepo::init(path));
})
test!(simple_git {
+ let td = TempDir::new("cargo").unwrap();
os::setenv("USER", "foo");
- assert_that(cargo_process("new").arg("foo"),
+ assert_that(cargo_process("new").arg("foo").cwd(td.path().clone()),
execs().with_status(0));
- assert_that(&paths::root().join("foo"), existing_dir());
- assert_that(&paths::root().join("foo/Cargo.toml"), existing_file());
- assert_that(&paths::root().join("foo/src/lib.rs"), existing_file());
- assert_that(&paths::root().join("foo/.git"), existing_dir());
- assert_that(&paths::root().join("foo/.gitignore"), existing_file());
+ assert_that(td.path(), existing_dir());
+ assert_that(&td.path().join("foo/Cargo.toml"), existing_file());
+ assert_that(&td.path().join("foo/src/lib.rs"), existing_file());
+ assert_that(&td.path().join("foo/.git"), existing_dir());
+ assert_that(&td.path().join("foo/.gitignore"), existing_file());
- assert_that(cargo_process("build").cwd(paths::root().join("foo")),
+ assert_that(cargo_process("build").cwd(td.path().clone().join("foo")),
execs().with_status(0));
})
test!(git_prefers_command_line {
let root = paths::root();
+ let td = TempDir::new("cargo").unwrap();
fs::mkdir(&root.join(".cargo"), USER_RWX).assert();
File::create(&root.join(".cargo/config")).write_str(r#"
[cargo-new]
email = "bar"
"#).assert();
- assert_that(cargo_process("new").arg("foo").arg("--git")
+ assert_that(cargo_process("new").arg("foo").arg("--git").cwd(td.path().clone())
.env("USER", Some("foo")),
execs().with_status(0));
- assert!(root.join("foo/.gitignore").exists());
+ assert!(td.path().join("foo/.gitignore").exists());
+})
+
+test!(subpackage_no_git {
+ os::setenv("USER", "foo");
+ assert_that(cargo_process("new").arg("foo"), execs().with_status(0));
+
+ let subpackage = paths::root().join("foo").join("components");
+ fs::mkdir(&subpackage, USER_RWX).assert();
+ assert_that(cargo_process("new").arg("foo/components/subcomponent"),
+ execs().with_status(0));
+
+ assert_that(&paths::root().join("foo/components/subcomponent/.git"),
+ is_not(existing_file()));
+ assert_that(&paths::root().join("foo/components/subcomponent/.gitignore"),
+ is_not(existing_file()));
})